<?php
/**
 * 
 * CodeSpace Client Controller Plugin
 * 
 * @access public
 * @package CodeSpace Client
 * @subpackage Client
 * @author Hüseyin Deniz KIVRAK <huseyindeniz@mikrobeta.com.tr>
 */
class CodeSpace_Client_Controller_Plugin_Client extends Zend_Controller_Plugin_Abstract{
    
    /**
     * options 
     * 
     * @var CodeSpace_Client_Controller_Plugin_Client options
     */
    private $_options = null;
    
    /**
     * 
     * constructor()
     * 
     */
    public function __construct()
    {

    }
    
	/**
     * 
     * routeStartup()
     * 
     */
    public function routeStartup (Zend_Controller_Request_Abstract $request)
    {
        $clientSettings = new Zend_Config_Ini(APPLICATION_PATH . '/configs/client.ini', 'settings');
        $this->_options = $clientSettings->toArray();
        
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $view = $viewRenderer->view;
        
        $view->addHelperPath("CodeSpace/Client/View/Helper", "CodeSpace_Client_View_Helper");
        
        $client = $_SERVER['HTTP_HOST'];
        $request->setParam('client', $client);

    }

	/**
     * 
     * routeShutdown()
     * 
     * sets the current client and subclient from uri param
     * 
     * @author Hüseyin Deniz KIVRAK <huseyindeniz@mikrobeta.com.tr>
     * @param Zend_Controller_Request_Abstract $request
     * @access public
     * @return null
     */    
    public function routeShutdown (Zend_Controller_Request_Abstract $request)
    {
        $client =  $request->getParam("client");
        $subclient = $request->getParam("subclient");
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $view = $viewRenderer->view;
        //exit;
        /*
        if ($view->client()->setClient($client)) {
            if(!$view->client()->setSubClient($subclient)){
                throw new Exception('Geçersiz sub client');
            }
        }else {
            throw new Exception('Geçersiz client');
        }
        */
    }
    
    public function postDispatch(Zend_Controller_Request_Abstract $request)
    {
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $view = $viewRenderer->view;
        
        $view->placeholder("clientMenu")->captureStart();
            include $this->_options['viewpath'] . "/client/clientMenu.phtml";
        $view->placeholder("clientMenu")->captureEnd();
        
        if(APPLICATION_ENV === 'development' || APPLICATION_ENV === 'testing')
        {
            $view->placeholder("clientProfiler")->captureStart();
                include $this->_options['viewpath'] . "/client/clientProfiler.phtml";
            $view->placeholder("clientProfiler")->captureEnd(); 
        }       
    }
}

?>